package org.peoples.tests.rooms;

import java.util.ArrayList;
import java.util.Date;

import junit.framework.TestCase;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.peoples.rooms.Room;
import org.peoples.rooms.RoomPool;

public class TestRoomPool extends TestCase {
	
	RoomPool rooms;
	ArrayList<Integer> roomIDs;
	
	public TestRoomPool(String name) {
		super(name);
	}
	
	@Before
	public void setUp() throws Exception {
		this.roomIDs = new ArrayList<Integer> ();
		
		rooms = RoomPool.getInstance();
		
		Room room1 = rooms.addRoom("Room 100", "Room 100 Description", new Date());
		Room room2 = rooms.addRoom("Room 101", "Room 101 Description", new Date());
		Room room3 = rooms.addRoom("Room 102", "Room 102 Description", new Date());
		
		try {
			roomIDs.add(room1.getRoomProperties().ID);
			roomIDs.add(room2.getRoomProperties().ID);
			roomIDs.add(room3.getRoomProperties().ID);
		} catch (Exception e) {
			//
		}
	}
	
	@After
	public void tearDown() throws Exception {
		rooms = null;
		roomIDs = null;
	}

	@Test
	public void testAddRoom() {
		Room room1 = rooms.addRoom("Room 1", "Room 1 Description", new Date());
		Room room2 = rooms.addRoom("Room 2", "Room 2 Description", new Date());
		Room room3 = rooms.addRoom("Room 1", "Room 1 Description", new Date());
		Room room4 = rooms.addRoom("Room 3", "Room 3 Description", new Date());
		
		assertNotNull(room1);
		assertNotNull(room2);
		assertNull("room3 should be null", room3);
		assertNotNull(room4);
	}

	@Test
	public void testGetInstance() {
		assertNotNull(RoomPool.getInstance());
	}

	@Test
	public void testGetAllRooms() {
		assertNotNull(rooms.getAllRooms());
	}

	@Test
	public void testGetRoom() {
		for (Integer id : roomIDs) {
			assertNotNull(rooms.getRoom(id));
		}
	}

	@Test
	public void testRemoveUser() {
		//fail("Not yet implemented");
	}

	@Test
	public void testRemoveRoom() {
		for (Integer id : roomIDs) {
			assertTrue(rooms.removeRoom(id));
		}
	}

}
